package 牛客;

import java.util.LinkedList;
import java.util.List;

public class 电话号码的字符组合 {
    static String[] mapping = new String[] {
            "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"
    };
    static List<String> res=new LinkedList<>();

    public static List<String> letterCombinations(String digits) {
        if(digits.isEmpty()){
            return  res;
        }
        back(digits,0,new StringBuilder());
        return res;
    }
    static void back(String digits,int start,StringBuilder sb){
        if(sb.length()==digits.length()){
            res.add(sb.toString());
            return;
        }
        for(int i=start;i<digits.length();i++){
            //取出数字
            int digit=digits.charAt(i)-'0';
            for (char c:mapping[digit].toCharArray()){
                sb.append(c);
                back(digits,i+1,sb);
                sb.deleteCharAt(sb.length()-1);
            }
        }
    }

    public static void main(String[] args) {
        System.out.println(letterCombinations("23"));
    }

}